﻿$(document).ready(function () {
});


function CopySiteAddressClick() {
    $("#EATRU_DetailsView1_SITE_ADD1").val($('#EATRU_DetailsView1_POST_ADDRESS_1').val());
    $("#EATRU_DetailsView1_SITE_SUBURB").val($('#EATRU_DetailsView1_POST_SUBURB').val());
    $("#EATRU_DetailsView1_SelSITE_STATE").val($('#EATRU_DetailsView1_SelPOST_STATE').val());
    $("#EATRU_DetailsView1_SITE_POSTCODE").val($('#EATRU_DetailsView1_POST_POSTCODE').val());
}



function NMIChangedEATRU() {
    var checkStr = $('#EATRU_DetailsView1_NMI').val();
    if (checkStr.length != 11) {
        //alert("NMI Must be 11 digits long");
    }
    else {
        var hash1 = { 0: "12", 1: "13", 2: "5", 3: "6", 4: "7", 5: "8", 6: "9", 7: "10", 8: "11", 9: "12" };
        var hash2 = { 0: "15", 1: "17", 2: "1", 3: "3", 4: "5", 5: "7", 6: "9", 7: "2", 8: "4", 9: "6" };

        var ch1 = parseInt(hash1[checkStr.charAt(0)]);
        var ch2 = parseInt(hash2[checkStr.charAt(1)]);
        var ch3 = parseInt(hash1[checkStr.charAt(2)]);
        var ch4 = parseInt(hash2[checkStr.charAt(3)]);
        var ch5 = parseInt(hash1[checkStr.charAt(4)]);
        var ch6 = parseInt(hash2[checkStr.charAt(5)]);
        var ch7 = parseInt(hash1[checkStr.charAt(6)]);
        var ch8 = parseInt(hash2[checkStr.charAt(7)]);
        var ch9 = parseInt(hash1[checkStr.charAt(8)]);
        var ch10 = parseInt(hash2[checkStr.charAt(9)]);
        var ch11 = parseInt(checkStr.charAt(10));

        var sum = ch1 + ch2 + ch3 + ch4 + ch5 + ch6 + ch7 + ch8 + ch9 + ch10;
        var chk = sum % 10 + ch11;

        if (chk != 10) {
            alert("NMI is NOT valid!" + chk);
            $('#EATRU_DetailsView1_NMI').focus();
        }
    }
}


function DPIChangedEATRU() {
    var checkStr = $('#EATRU_DetailsView1_DPI').val();
    if (checkStr.length != 11) {
        //alert("DPI Must be 11 digits long");
    }
    else {
        var hash1 = { 0: "12", 1: "13", 2: "5", 3: "6", 4: "7", 5: "8", 6: "9", 7: "10", 8: "11", 9: "12" };
        var hash2 = { 0: "15", 1: "17", 2: "1", 3: "3", 4: "5", 5: "7", 6: "9", 7: "2", 8: "4", 9: "6" };

        var ch1 = parseInt(hash1[checkStr.charAt(0)]);
        var ch2 = parseInt(hash2[checkStr.charAt(1)]);
        var ch3 = parseInt(hash1[checkStr.charAt(2)]);
        var ch4 = parseInt(hash2[checkStr.charAt(3)]);
        var ch5 = parseInt(hash1[checkStr.charAt(4)]);
        var ch6 = parseInt(hash2[checkStr.charAt(5)]);
        var ch7 = parseInt(hash1[checkStr.charAt(6)]);
        var ch8 = parseInt(hash2[checkStr.charAt(7)]);
        var ch9 = parseInt(hash1[checkStr.charAt(8)]);
        var ch10 = parseInt(hash2[checkStr.charAt(9)]);
        var ch11 = parseInt(checkStr.charAt(10));

        var sum = ch1 + ch2 + ch3 + ch4 + ch5 + ch6 + ch7 + ch8 + ch9 + ch10;
        var chk = sum % 10 + ch11;

        if (chk != 10) {
            alert("DPI is NOT valid!" + chk);
            $('#EATRU_DetailsView1_DPI').focus();
        }
    }
}


function ABNChangedEATRU() {

    var checkStr = $('#EATRU_DetailsView1_ABN').val();

    //var abn_fmt_str = (fmt_str) ? ‘\nThe ABN is a unique 11 digit number formed from a 9 digit unique identifier and two prefix check digits.\nThe Australian Business Register structure an ABN as XX XXX XXX XXX to assist readability.’ : ”;
    if (checkStr.length != 11 && checkStr.length != 14) {
        alert("ABN Must be 11 or 14 digits long");
    }
    else {
        var ch1 = parseInt(checkStr.charAt(0));
        var ch2 = parseInt(checkStr.charAt(1));
        var ch3 = parseInt(checkStr.charAt(2));
        var ch4 = parseInt(checkStr.charAt(3));
        var ch5 = parseInt(checkStr.charAt(4));
        var ch6 = parseInt(checkStr.charAt(5));
        var ch7 = parseInt(checkStr.charAt(6));
        var ch8 = parseInt(checkStr.charAt(7));
        var ch9 = parseInt(checkStr.charAt(8));
        var ch10 = parseInt(checkStr.charAt(9));
        var ch11 = parseInt(checkStr.charAt(10));

        var sum = 10 * (ch1 - 1) + ch2 + 3 * ch3 + 5 * ch4 + 7 * ch5 + 9 * ch6 + 11 * ch7 + 13 * ch8 + 15 * ch9 + 17 * ch10 + 19 * ch11;

        var chk = sum % 89;

        if (chk != 0) {
            alert("ABN is NOT valid!");
            $('#EATRU_DetailsView1_ABN').focus();
        }

    }

}
